const app = getApp()
Page({
  data: {
    imageUrl: app.globalData.imageUrl,
    curIndex: 0,
    curpage: 1,
    keywords: '',
    hasmore: true,
    member_list: []
  },
  onLoad: function (options) {
    var self = this;
    wx.getStorage({
      key: 'key',
      success: res => {
        self.data.key = res.data;
        self.getMemberInfo();
      }
    })
  },
  changeIndex: function (e) {
    this.setData({
      curIndex: e.currentTarget.dataset.index
    })
    let level = e.currentTarget.dataset.index * 1 + 1;
    this.data.curpage = 1;
    this.data.hasmore = true;
    this.data.member_list = [];
    this.getMemberInfo(level)
  },
  getMemberInfo: function (level = 1) {
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=commander_member_list',
      data: {
        key: self.data.key,
        level: level,
        curpage: self.data.curpage,
        keywords: self.data.keywords
      },
      method: 'GET',
      success: function (res) {
        if (res.data.code == 200) {
          self.setData({
            member_list: self.data.member_list.concat(res.data.datas.member_list),
            hasmore: res.data.hasmore
          })
        }
        if (res.data.hasmore) {
          self.data.curpage++;
        }
      }
    })
  },
  getMoreInfo: function () {
    if (this.data.hasmore) {
      this.getMemberInfo()
    }
  },
  getKeywords: function (e) {
    this.data.keywords = e.detail.value;
  },
  search: function () {
    this.data.curpage = 1;
    this.data.hasmore = true;
    this.data.member_list = [];
    this.getMemberInfo()
  }
})